﻿using System;
using System.Data;
using System.Linq;
using WPFExcelReport.Helpers;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public partial class ITXEXRPT
    {

        private void JLTABGB52(DataSet db)
        {
            try
            {
                #region------------------准确的格式---
                //DataTable tbVKPOS = db.Tables["VKPOS"];
                //DataTable dtOutput = new DataTable();
                //int idx = 1;
                //#region======Title===========
                //exAgent.SetCellValue(2, idx++, "品种号"); dtOutput.Columns.Add("VKPART", typeof(System.String));
                //exAgent.SetCellValue(2, idx++, "花型号"); dtOutput.Columns.Add("VKPFARBE", typeof(System.String));         
                //exAgent.SetCellValue(2, idx++, "订单数量"); dtOutput.Columns.Add("VKPMENGE1", typeof(System.String));
                //exAgent.SetCellValue(2, idx++, "单位"); dtOutput.Columns.Add("VKPMEEH", typeof(System.String));
                //exAgent.SetCellValue(2, idx++, "交期"); dtOutput.Columns.Add("VKPLIEFTERM", typeof(System.String));
                //exAgent.SetCellValue(2, idx++, "贸易条件"); dtOutput.Columns.Add("VKKLIEFBED", typeof(System.String));
                //exAgent.SetCellValue(2, idx++, "业务员"); dtOutput.Columns.Add("VKKSACHBE", typeof(System.String));
                //exAgent.SetCellValue(2, idx++, "客户"); dtOutput.Columns.Add("KDKUNDNA", typeof(System.String));
                //exAgent.SetCellValue(2, idx++, "目的地"); 
                //exAgent.SetCellValue(2, idx++, "港口"); 
                //#endregion
                //dtOutput.Merge(tbVKPOS, false, MissingSchemaAction.Ignore);
                //exAgent.DataTableToExcel(dtOutput, 3, 1);
                //exAgent.SetCellValue(1, 1, 1);
                //int count = dtOutput.Rows.Count;
                //exAgent.BatchConvert2Number(3, 3, count + 2, 3);
                //exAgent.BatchConvert2Number(3, 5, count + 2, 5);
                //exAgent.SetCellValue(1, 1, "销售服务查询");
                #endregion
                 DataTable tbVKPOS = db.Tables["ABPOS"];  
                DataTable dtOutput = new DataTable();
                int idx = 1;
                exAgent.SetCellValue(1, 1, "染色查询");
                exAgent.SetCellValue(2, idx++, "染色"); dtOutput.Columns.Add("ABPAUFKRS", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "单号"); dtOutput.Columns.Add("ABPAUFLFD", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "行号"); dtOutput.Columns.Add("ABPAUFPOS", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "第几批"); dtOutput.Columns.Add("ABAAPOS", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "纱线名称"); dtOutput.Columns.Add("ABPART", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "色号"); dtOutput.Columns.Add("ABPFARBE", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "颜色"); dtOutput.Columns.Add("GSCBEZ", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "计划下锅数"); dtOutput.Columns.Add("ABPSOLLMENGE7", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "计划重量"); dtOutput.Columns.Add("ABPSOLLMENGE5", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "染批"); dtOutput.Columns.Add("ABAKDPARTIE", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "个数"); dtOutput.Columns.Add("ABABEM1", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "重量"); dtOutput.Columns.Add("ABABEM2", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "时间"); dtOutput.Columns.Add("ABAVERSDAT", typeof(System.String));
                exAgent.SetCellValue(2, idx++, "倒筒"); dtOutput.Columns.Add("ABPZUGSTK", typeof(System.String));
             
             
                dtOutput.Merge(tbVKPOS, false, MissingSchemaAction.Ignore);               
              
                string GSCBEZ=""; 
                string ABAVERSDAT = "";


                foreach (DataRow VKP in dtOutput.Rows)
                {
                    string str1 = "";
                    string str2 = "";
                    string str3 = "";
                   /*  DataRow VKP = tbVKPOS.Rows[i];
                     ABPAUFKRS = VKP["ABPAUFKRS"].ToString().Trim();
                     ABPAUFLFD = VKP["ABPAUFLFD"].ToString().Trim();
                     ABPAUFPOS = VKP["ABPAUFPOS"].ToString().Trim();
                     ABAAPOS = VKP["ABAAPOS"].ToString().Trim();
                     ABPART = VKP["ABPART"].ToString().Trim();
                     ABPFARBE = VKP["ABPFARBE"].ToString().Trim();*/
                    GSCBEZ = VKP["GSCBEZ"].ToString().Trim();
                    GSCBEZ = Helper.GetGB2312Value(GSCBEZ).Trim();
                    VKP["GSCBEZ"] = GSCBEZ;
                  //  ABPSOLLMENGE5 = VKP["ABPSOLLMENGE5"].ToString().Trim();
                 //   ABPSOLLMENGE7 = VKP["ABPSOLLMENGE7"].ToString().Trim();
                  //  ABAKDAUFTNR = VKP["ABAKDAUFTNR"].ToString().Trim();
                  //  ABAKDPARTIE = VKP["ABAKDPARTIE"].ToString().Trim();
                  //  ABABEM1 = VKP["ABABEM1"].ToString().Trim();
                  //  ABABEM2 = VKP["ABABEM2"].ToString().Trim();
                    try
                    {
                        ABAVERSDAT = VKP["ABAVERSDAT"].ToString().Trim();
                        Helper.GetSplitDate(ref str1, ref str2, ref str3, ABAVERSDAT);
                        //ABAVERSDAT = str3;
                        VKP["ABAVERSDAT"] = str3;// double.Parse(str3);

                    }
                    catch(Exception ex)
                    {
                       
                    }
                   
                    /*
                     *  ABPZUGSTK = VKP["ABPZUGSTK"].ToString().Trim();   
                    exAgent.SetCellValue(i + 3, 1, ABPAUFKRS);
                    exAgent.SetCellValue(i + 3, 2, ABPAUFLFD);
                    exAgent.SetCellValue(i + 3, 3, ABPAUFPOS);
                    exAgent.SetCellValue(i + 3, 4, ABAAPOS);
                    exAgent.SetCellValue(i + 3, 5, ABPART);
                    exAgent.SetCellValue(i + 3, 6, ABPFARBE);
                    exAgent.SetCellValue(i + 3, 7, GSCBEZ);
                    exAgent.SetCellValue(i + 3, 8, ABPSOLLMENGE5);
                    exAgent.SetCellValue(i + 3, 9, ABPSOLLMENGE7);
                    exAgent.SetCellValue(i + 3, 10, ABAKDAUFTNR);
                    exAgent.SetCellValue(i + 3, 11, ABAKDPARTIE);
                    exAgent.SetCellValue(i + 3, 12, ABABEM1);
                    exAgent.SetCellValue(i + 3, 13, ABABEM2);
                    exAgent.SetCellValue(i + 3, 14, ABAVERSDAT);
                    exAgent.SetCellValue(i + 3, 15, ABPZUGSTK);*/
                }
                #region====Excel==========
                int count = dtOutput.Rows.Count;
                exAgent.RangeCopy(3, 50, 5, 3 + count);
                exAgent.DataTableToExcel(dtOutput, 3, 1);
                //exAgent.SetCellValue(1, 1, 1);
                //exAgent.BatchConvert2Number(5, 16, count + 3, 19);
                exAgent.SetCellValue(1, 1, " ");
                #endregion
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        } 
    }
}